#include <cstdio>

typedef unsigned int uint;


inline int get_uint (uint &n)
{
	return scanf ("%u", &n);
}


inline int reverse (uint n)
{
	uint r = 0, d;

	while (n)
	{
		d = n % 10;
		n /= 10;
		r *= 10;
		r += d;
	}

	return r;
}


inline bool is_palindrome (uint n, uint &r)
{
	r = reverse (n);
	return n == r;
}

inline bool is_not_palindrome (uint n, uint &r)
{
	r = reverse (n);
	return n != r;
}


int main ()
{
	uint test_cases, iterations, n, r;

	get_uint (test_cases);
	while (test_cases--)
	{
		get_uint (n);
		for (iterations = 0; is_not_palindrome (n, r); ++iterations)
			n += r;
		printf("%u %u\n", iterations, n);
	}

	return 0;
}